package com.cry.todo.domain.audit;

import org.hibernate.envers.RevisionListener;

import com.cry.app.core.SpringApplicationContext;
import com.cry.core.security.UserDetailsService;
import com.cry.todo.domain.User;

public class AuditRevisionListener implements RevisionListener {

	@Override
	public void newRevision(Object revisionEntity) {
		UserDetailsService userDetailsService = (UserDetailsService) SpringApplicationContext.getBean("userDetailsService");

		User user = userDetailsService.getSessionUser();
		
		AuditRevisionEntity revEntity = (AuditRevisionEntity) revisionEntity; 
		User myUser = new User();
		myUser.setId(user.getId());
		revEntity.setModifiedBy(myUser);
	}

}
